package com.dh.leetcode.five;

import org.junit.Assert;
import org.junit.Test;

/**
 * 509. Fibonacci Number
 * <p>
 * https://leetcode.com/problems/fibonacci-number/
 */
public class _509_FibonacciNumber {

    public int fib(int n) {
        if (n == 0) {
            return 0;
        }
        int[] array = new int[3];
        array[2] = 1;
        for (int i = 0; i < n; i++) {
            if (i == 0 || i == 1) {
                array[0] = 1;
                array[1] = 1;
            } else {
                array[2] = array[0] % 1000000007 + array[1] % 1000000007;
                array[0] = array[1] % 1000000007;
                array[1] = array[2] % 1000000007;
            }
        }
        return array[2] % 1000000007;
    }

    @Test
    public void testFib() {
        System.out.println(
                701408733 - Integer.MAX_VALUE);
        Assert.assertEquals(0, fib(0));
        Assert.assertEquals(1, fib(1));
        Assert.assertEquals(1, fib(2));
        Assert.assertEquals(2, fib(3));
        Assert.assertEquals(3, fib(4));
        Assert.assertEquals(5, fib(5));
        Assert.assertEquals(8, fib(6));
        System.out.println(fib(43));
        System.out.println(fib(44));
        System.out.println(fib(48));
    }

}
